import {
	baseUrl
} from '@/util/config.js'
export const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		let token = uni.getStorageSync('X-Access-Token')
		console.log(options.data)
		// 在登录的时候需要储存 token uni.setStorageSync("authorization","这里是登录获取的token值")
		uni.request({
			url: options.ifToken ? baseUrl + options.url : baseUrl + options.url +
				`?token=${token}`,
			data: options.data || {},
			method: options.method || 'get',
			// sslVerify:false,
			header: {
				"Authorization": token,
				"client-source": "wx",
			},
			success: (res) => {
				// console.log('123123')
				console.log(res.data.code == '500'&&res.data.msg === "token失效")
				// 控制台显示数据信息
				if (res.data.code == '401') {
					uni.clearStorage()
					// uni.reLaunch({
					// 	url: '/pages/expressPages/expressPages',
					// })
				}else if(res.data.code == '500'&&res.data.msg === "token失效"){
					// console.log('123123')
					uni.clearStorage()
					/* uni.reLaunch({
						url: '/pages/index/index',
					}) */
					// return
					// resolve(res.data)
				}
				else {
					resolve(res.data)
				}
			},
			fail: (err) => {
				// console.log('123123')
				
				console.log(err);
				reject(err)
			},
			catch: (e) => {
				console.log(e);
			}
		})
	})
}
// 将对象导出外部引入使用
// export default {
// 	myRequest
// }